#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline void read(int& x){
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()){if(ch=='-')f=-1;}
    for(;isdigit(ch);ch=getchar()){x=(x<<3)+(x<<1);x+=(int)ch-'0';}x*=f;
}
const int N=2e5+5;
int T;
int n;
int a[N];
int col[N];
ll ans;
void init(){
    memset(col,0,sizeof(col));
    ans=0;
}

void dfs(int dep){
    if(dep>n){
        ll c=0;
        int pos=1e9;
        for(int i=1;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(col[j]==col[i]){
                    if(a[i]==a[j]){
                        c+=a[i];
                    }
                    break;
                }
            }
        }
        ans=max(ans,c);
        return ;
    }
    col[dep]=1;
    dfs(dep+1);
    col[dep]=2;
    dfs(dep+1);
}

void work1(){
    dfs(1);
    cout<<ans<<endl;
    return ;
}


int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while(T--){
        init();
        read(n);
        for(int i=1;i<=n;i++){
            read(a[i]);
        }
        if(n<=15){
            work1();
        }
    }
    return 0;
}